/*
 * Standard Star prelude
 */
import base;         -- stuff that is core to all star base
import validate;     -- Standard validation rules
import formatter;
import macrosupport; -- Support for compiled macros

-- Standard macros

import updateable;
import arithmetic;
import casting;
import iterable;
import actors;
import arrays;
import relations;
import queue;
import cons;
import dateNtime;
import sequences;
import strings;
import folding;
import threads;
import maps;
import compute;

-- used in processing ordered queries
contract _project0 over %%c is {
  __project0 has type (%%c of ((%k,%v))) => %%c of %k;
  __unique has type (%%c of %e,(%e,%e)=>boolean) => %%c of %e;
}

implementation _project0 over array is {
  __project0(A) is __array_project_0(A);
  __unique(A,E) is __array_unique(A,E);
}

implementation _project0 over relation is {
  __project0(A) is __relation_project_0(A);
  __unique(R,E) is __relation_unique(R,E);
}

contract iotaC over (%%r,%t) is {
  iota has type (%t,%t,%t) => %%r of %t
};

implementation iotaC over (array,integer) is {
  iota(integer(F),integer(T),integer(S)) is __integer_array_iota(F,T,S);
}

implementation iotaC over (array,long) is {
  iota(long(F),long(T),long(S)) is __long_array_iota(F,T,S);
}

implementation iotaC over (array,float) is {
  iota(float(F),float(T),float(S)) is __float_array_iota(F,T,S);
}

implementation iotaC over (cons,integer) is {
  iota(F,T,S) where S>0 is iotaF(F,T,S);
  iota(F,T,S) default is iotaB(F,T,S);
  
  private iotaF(F,T,S) where F>T is nil;
  iotaF(F,T,S) is cons(F,iotaF(F+S,T,S));
  
  private iotaB(F,T,S) where F<T is nil;
  iotaB(F,T,S) is cons(F,iotaB(F+S,T,S));
}

-- macro out common use case ...
# #(for #(identifier?C)# in iota(?S,?L,?St) do ?A)# ==> {
  var C := S;
  while C<= L do{
    A;
    C := C+St;
  }
};